const express = require('express')
// 创建路由对象
const router = express.Router()
// 引入表单验证规则
const expressJoi = require('@escook/express-joi')
// 引入电话号码验证规则
const { phoneValidator, bus_user_register, bus_user_forget_schema } = require('../schema/getCode')
// 引入发送验证码处理函数
const { getCode } = require('../router_handler/getCode')
// 商家用户路由处理函数
const { pusUserRegister, pusUserLogin, forgetPassword } = require('../router_handler/busUser')
// 商家参数验证对象
const { bus_user_login_schema } = require('../schema/busUserSchema')
// 普通用户路由处理函数
const { userLogin, userRegister, userForget, getBannerGoods, getHotGoods, getRecommendGoods, getNewGoodsList, getAntherGoodsList, getGoodsInfoById, getAllGoodsByCateId, getCateOneLevel, getCateTwoLevel, getHotSearch, searchHandler } = require('../router_handler/user')
// 普通用户参数验证规则
const { user_register, user_login_schema, user_forget_schema, get_new_goods_schema, get_another_goods_schema, get_all_goods_by_cate_id, get_one_level_schema, search_keyword_schema } = require('../schema/userSchema')

// 获取验证码
router.post('/getcode', expressJoi(phoneValidator), getCode)

//#region 商家
// 商家用户注册账户
router.post('/pus/register', expressJoi(bus_user_register), pusUserRegister)

// 商家用户登录
router.post('/bus/login', expressJoi(bus_user_login_schema), pusUserLogin)

// 商家用户找回密码
router.post('/bus/forget', expressJoi(bus_user_forget_schema), forgetPassword)
//#endregion

//#region 普通用户
// 普通用户注册账号
router.post('/user/register', expressJoi(user_register), userRegister)

// 普通用户登录
router.post('/user/login', expressJoi(user_login_schema), userLogin)

// 普通用户忘记密码
router.post('/user/forget', expressJoi(user_forget_schema), userForget)

// 获取首页轮播图
router.get('/user/goods/banner', getBannerGoods)

// 获取最新商品
router.get('/user/new/goods', expressJoi(get_new_goods_schema), getNewGoodsList)

// 获取热卖商品
router.get('/user/hot', getHotGoods)

// 获取店铺推荐商品
router.get('/user/recommend/goods', expressJoi(get_new_goods_schema), getRecommendGoods)

// 获取其他商品
router.get('/user/goods/list', expressJoi(get_another_goods_schema), getAntherGoodsList)

// 获取商品详情信息
router.get('/user/goods/detail/:id', getGoodsInfoById)

// 根据分类id获取商品数据
router.get('/user/get/goods/list', expressJoi(get_all_goods_by_cate_id), getAllGoodsByCateId)

// 获取一级分类
router.get('/user/cate/one', getCateOneLevel)
// 获取二级分类
router.get('/user/cate/two', expressJoi(get_one_level_schema), getCateTwoLevel)

// 获取热门搜索
router.get('/hot/search', getHotSearch)

// 根据关键字搜索商品数据
router.get('/search', expressJoi(search_keyword_schema), searchHandler)

//#endregion

// 导出路由对象
module.exports = router
